<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/fcdb/css/x-admin.css" media="all">
</head>

<body>

<div class="x-body">
        	  <form class="layui-form" method="post" action="">
                      <div class="layui-form-item">
                          <label for="username" class="layui-form-label">
                              <span class="x-red">*</span>用户名
                          </label>
                          <div class="layui-input-inline">
                              <input type="hidden" id ="id" value="${map.user.pkUserId}" name="id">
                              <input type="text" id="userName" name="userName" value="${map.user.userName}" required="" lay-verify="required"
                                     autocomplete="off" class="layui-input">
                          </div>
                          <div class="layui-form-mid layui-word-aux">
                              <span class="x-red">*</span>您唯一的登入名
                          </div>
                      </div>
                  <div class="layui-form-item">
                      <label for="userCode" class="layui-form-label">
                          <span class="x-red">*</span>工号
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="userCode" name="userCode" value="${map.user.userCode}" required="" lay-verify="required"
                                 autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>您的编号
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="phoneNum" class="layui-form-label">
                          <span class="x-red">*</span>电话
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="phoneNum" name="phoneNum" value="${map.user.phoneNum}" required="" lay-verify="required"
                                 autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>您的电话
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="email" class="layui-form-label">
                          <span class="x-red">*</span>邮箱
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="email" name="email" value="${map.user.email}" required="" lay-verify="required"
                                 autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>您的邮箱
                      </div>
                  </div>
                      <div class="layui-form-item">
                          <label for="password" class="layui-form-label">
                              <span class="x-red">*</span>密码
                          </label>
                          <div class="layui-input-inline">
                              <input type="password" id="password" name="password" disabled="disabled" value="********" required="" lay-verify="pass"
                                     autocomplete="off" class="layui-input">
                          </div>
                          <div class="layui-form-mid layui-word-aux">
                              6到16个字符
                          </div>
                      </div>
                      <div class="layui-form-item">
                          <label for="roleId" class="layui-form-label">
                              <span class="x-red">*</span>角色
                          </label>
                          <div class="layui-input-inline">
                              <select id="roleId" name="roleId" required="" lay-verify="required">
                                  <c:forEach var="item"   items="${map.roles}"   varStatus="status">

                                      <option value="${item.pkRoleId}"
                                      <c:if test="${(item.pkRoleId)==(map.myRole.pkRoleId)}">
                                          selected="selected"
                                      </c:if>
                                      >${item.roleName}</option>

                                  </c:forEach>
                              </select>
                          </div>
                      </div>


                      <div class="layui-form-item">
                          <div class="layui-input-block">
                              <button class="layui-btn" lay-submit lay-filter="save">保存</button>
                          </div>
                      </div>
	          </form>
</div>
<script src="/fcdb/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/fcdb/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function(value){
                if(value.length < 5){
                    return '昵称至少得5个字符啊';
                }
            }
        });

        //监听提交
        form.on('submit(save)', function(data){
            $.ajax({
                url:"/fcdb/user/saveOrUpdate.do",
                dataType:"json",
                data:{
                    pkUserId:$("#id").val(),
                    userName:$("#userName").val(),
                    userCode:$("#userCode").val(),
                    phoneNum:$("#phoneNum").val(),
                    email:$("#email").val(),
                    roleId:$("#roleId").val(),
                },
                type:"POST",
                async:false,
                success:function (res) {
                    if(res.msg=="success"){
                        layer.alert("编辑成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg("增加失败", {icon: 1});
                    }
                },
                error:function (XMLHttpRequest) {
                    layer.msg("系统错误", {icon: 1});
                }
            })
            return false;
        });


    });
</script>
</body>
</html>